<?php
class SingletonPDO {
	private $PDOInstance = null;
	private static $instance = null;

	private function __construct()
	{
		try {
			$this->PDOInstance = new MyPDO(CFG_DB_DSN, USER_DB, MDP_BD,array(
			    PDO::ATTR_PERSISTENT => true,
			    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
			    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
			));
		}
		catch(PDOException $e) {
			throw new Exception("Erreur de connexion PDO");
		}
	}

	public static function getInstance()
	{
		if (is_null(self::$instance)) {
			self::$instance = new SingletonPDO();
		}
		return self::$instance;
	}

	public function prepare($query)
	{
		return $this->PDOInstance->prepare($query);
	}

	public function query($query)
	{
		try {
			return $this->PDOInstance->query($query);
		}
		catch(PDOException $e) {
			echo $query;
			die("Erreur : " . $e->getMessage());
		}
	}

	public function exec($query)
	{
		return $this->PDOInstance->exec($query);
	}

	public function lastInsertId()
	{
		return $this->PDOInstance->lastInsertId();
	}

	public function beginTransaction()
	{
		return $this->PDOInstance->beginTransaction();
	}

	public function inTransaction()
	{
		return $this->PDOInstance->inTransaction();
	}

	public function rollback()
	{
		return $this->PDOInstance->rollback();
	}

	public function commit()
	{
		return $this->PDOInstance->commit();
	}
}
?>